package commonService

import (
	"context"
	"encoding/json"
	"fmt"
	"github.com/Sir-yuChen/funAnalyse/global"
	"github.com/Sir-yuChen/funAnalyse/model"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

func GetUserInfoByToken(c *gin.Context) (*model.StockUser, error) {
	var userInfo model.StockUser
	token, _ := c.Get("token")
	customerId, _ := c.Get("customerId")
	result, err := global.GVA_REDIS.Get(context.Background(), fmt.Sprint(token)).Result()
	err = json.Unmarshal([]byte(result), &userInfo) //json转struct
	if err != nil {
		global.GVA_LOG.Error("根据token 获取用户详情异常", zap.Any("customerId", customerId), zap.Error(err))
		return nil, err
	}
	return &userInfo, nil
}
